﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC.api.Application.commond.culture;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto.ProSorce;
using RBAC.Common.Dto;
using RBAC.Enum;

namespace RBAC.api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SourceController1 : ControllerBase
    {


        private readonly IMediator _mediator;

        public SourceController1(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 溯源下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Rulst> Sourse(SourceManageCommond request, CancellationToken cancellationToken)
        {

            var list = await _mediator.Send(request);
            return list;

        }
        /// <summary>
        /// 商品下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Rulst> Goodsslect(GoodsSelectCommond request, CancellationToken cancellationToken)
        {


            var reault = await _mediator.Send(request);


            return reault;

        }

        /// <summary>
        /// 商品基本信息添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Rulst> ProductionBaseicMessAdd(ProductionBasicMessCommond request, CancellationToken cancellationToken)
        {
            var query= await _mediator.Send(request);
            return query;




        }

        /// <summary>
        /// 图片上传
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GETimages(IFormFile file)
        {


            var filename = file.FileName;

            filename=DateTime.Now.ToString("yyyyMMDDhhss")+Path.GetExtension(filename);

            var path=Directory.GetCurrentDirectory()+"\\wwwroot\\PUT\\"+filename;


            using(FileStream fs=new FileStream(path,FileMode.Create))
            {
                file.CopyTo(fs);
                fs.Flush();
            }
            var sur = "/PUT/" + filename;

            return Ok(sur); 

        }
        /// <summary>
        /// 溯源管理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Rulst> SourceHtml(SourceHtmlCommond request, CancellationToken cancellationToken)
        {

            var query = await _mediator.Send(request);

            return query;



        }

        /// <summary>
        /// 获取我们的商品基本信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Rulst> GoosMess(CultureRevealCommond request, CancellationToken cancellationToken)
        {

            var query = await _mediator.Send(request);


            return query;


        }
        /// <summary>
        /// 产品合格图片添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Rulst> Handle(CutlerRevealImagesCommond request, CancellationToken cancellationToken)
        {

            var query = await _mediator.Send(request);

            return query;

        }
        /// <summary>
        /// 删除图片
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Rulst> Deel(CutlerDeelImagesCommond request, CancellationToken cancellationToken)
        {
            var query = await _mediator.Send(request);

            return query;

        }




    }
}
